{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8113820b",
   "metadata": {},
   "source": [
    "# Python不仅仅是个计算器\n",
    "## 我们今天来玩表格\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6be79caf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            open  high   low  close\n",
       "date                               \n",
       "2022-07-01  2.78  2.79  2.76   2.77\n",
       "2022-07-04  2.77  2.77  2.75   2.76\n",
       "2022-07-05  2.77  2.78  2.74   2.76\n",
       "2022-07-06  2.76  2.76  2.70   2.72\n",
       "2022-07-07  2.72  2.74  2.71   2.72"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from localdata import anyone, daily\n",
    "data, code, name = anyone(klen = 5)\n",
    "\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "a399f5d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "让我们看看sh.600567山鹰国际的日K线\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            open  high   low  close\n",
       "date                               \n",
       "2022-07-01  2.78  2.79  2.76   2.77\n",
       "2022-07-04  2.77  2.77  2.75   2.76\n",
       "2022-07-05  2.77  2.78  2.74   2.76\n",
       "2022-07-06  2.76  2.76  2.70   2.72\n",
       "2022-07-07  2.72  2.74  2.71   2.72"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print('让我们看看' + code + name + '的日K线')\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ed4e0da",
   "metadata": {},
   "source": [
    "### 了解这个表格\n",
    "#### 表格概况"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "0e361d81",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5, 4)"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "78c96ed9",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2022-07-01', '2022-07-04', '2022-07-05', '2022-07-06',\n",
       "               '2022-07-07'],\n",
       "              dtype='datetime64[ns]', name='date', freq=None)"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "8d05ed9b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['open', 'high', 'low', 'close'], dtype='object')"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "3c51132a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "DatetimeIndex: 5 entries, 2022-07-01 to 2022-07-07\n",
      "Data columns (total 4 columns):\n",
      " #   Column  Non-Null Count  Dtype  \n",
      "---  ------  --------------  -----  \n",
      " 0   open    5 non-null      float64\n",
      " 1   high    5 non-null      float64\n",
      " 2   low     5 non-null      float64\n",
      " 3   close   5 non-null      float64\n",
      "dtypes: float64(4)\n",
      "memory usage: 200.0 bytes\n"
     ]
    }
   ],
   "source": [
    "data.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "9247370f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>2.760000</td>\n",
       "      <td>2.768000</td>\n",
       "      <td>2.732000</td>\n",
       "      <td>2.746000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.023452</td>\n",
       "      <td>0.019235</td>\n",
       "      <td>0.025884</td>\n",
       "      <td>0.024083</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>2.720000</td>\n",
       "      <td>2.740000</td>\n",
       "      <td>2.700000</td>\n",
       "      <td>2.720000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>2.760000</td>\n",
       "      <td>2.760000</td>\n",
       "      <td>2.710000</td>\n",
       "      <td>2.720000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>2.770000</td>\n",
       "      <td>2.770000</td>\n",
       "      <td>2.740000</td>\n",
       "      <td>2.760000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>2.770000</td>\n",
       "      <td>2.780000</td>\n",
       "      <td>2.750000</td>\n",
       "      <td>2.760000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>2.780000</td>\n",
       "      <td>2.790000</td>\n",
       "      <td>2.760000</td>\n",
       "      <td>2.770000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           open      high       low     close\n",
       "count  5.000000  5.000000  5.000000  5.000000\n",
       "mean   2.760000  2.768000  2.732000  2.746000\n",
       "std    0.023452  0.019235  0.025884  0.024083\n",
       "min    2.720000  2.740000  2.700000  2.720000\n",
       "25%    2.760000  2.760000  2.710000  2.720000\n",
       "50%    2.770000  2.770000  2.740000  2.760000\n",
       "75%    2.770000  2.780000  2.750000  2.760000\n",
       "max    2.780000  2.790000  2.760000  2.770000"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9ecd2267",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            open  high   low  close\n",
       "date                               \n",
       "2022-07-01  2.78  2.79  2.76   2.77\n",
       "2022-07-04  2.77  2.77  2.75   2.76\n",
       "2022-07-05  2.77  2.78  2.74   2.76\n",
       "2022-07-06  2.76  2.76  2.70   2.72\n",
       "2022-07-07  2.72  2.74  2.71   2.72"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d4a2242",
   "metadata": {},
   "source": [
    "### 换个标题（列名） \n",
    "- data的rename方法不改变data本身，并返回一份新的（内容跟原来稍有改变）数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "bb56743e",
   "metadata": {},
   "outputs": [],
   "source": [
    "age = 15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "7e2255d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 # 标量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "c3f983ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 标量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "cc54ffdf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "16\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "age = 13 + 3\n",
    "print(age)\n",
    "age = 3+4\n",
    "print(age)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "0d7bd000",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "16\n"
     ]
    }
   ],
   "source": [
    "age = 13 + 3\n",
    "print(age)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "84f930a8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'十五岁'"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'十五岁'  # 标量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "5cf5888d",
   "metadata": {},
   "outputs": [],
   "source": [
    "age = '十五岁'  # 赋值语句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "a42a8edd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age # 变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "6583b3a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "age = \"十九\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "e10710e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cbe55d11",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e20f54c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "9d7e4e0b",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataWithCName = data.rename({'open': '开盘价'}, axis = 'columns')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "0a8c4ffa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>开盘价</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             开盘价  high   low  close\n",
       "date                               \n",
       "2022-07-01  2.78  2.79  2.76   2.77\n",
       "2022-07-04  2.77  2.77  2.75   2.76\n",
       "2022-07-05  2.77  2.78  2.74   2.76\n",
       "2022-07-06  2.76  2.76  2.70   2.72\n",
       "2022-07-07  2.72  2.74  2.71   2.72"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataWithCName "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "9fc05977",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>开盘价</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>收盘价</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             开盘价  high   low   收盘价\n",
       "date                              \n",
       "2022-07-01  2.78  2.79  2.76  2.77\n",
       "2022-07-04  2.77  2.77  2.75  2.76\n",
       "2022-07-05  2.77  2.78  2.74  2.76\n",
       "2022-07-06  2.76  2.76  2.70  2.72\n",
       "2022-07-07  2.72  2.74  2.71  2.72"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataWithCName.rename({'close': '收盘价'}, axis = 'columns')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "f017c141",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>开盘价</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             开盘价  high   low  close\n",
       "date                               \n",
       "2022-07-01  2.78  2.79  2.76   2.77\n",
       "2022-07-04  2.77  2.77  2.75   2.76\n",
       "2022-07-05  2.77  2.78  2.74   2.76\n",
       "2022-07-06  2.76  2.76  2.70   2.72\n",
       "2022-07-07  2.72  2.74  2.71   2.72"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataWithCName"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d94f9ac4",
   "metadata": {},
   "source": [
    "- 使用了 inplace=True 参数后，执行原地修改，即改变本身的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "cf631480",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>开盘价</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>收盘价</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             开盘价  high   low   收盘价\n",
       "date                              \n",
       "2022-07-01  2.78  2.79  2.76  2.77\n",
       "2022-07-04  2.77  2.77  2.75  2.76\n",
       "2022-07-05  2.77  2.78  2.74  2.76\n",
       "2022-07-06  2.76  2.76  2.70  2.72\n",
       "2022-07-07  2.72  2.74  2.71  2.72"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataWithCName.rename({'close': '收盘价'}, axis = 'columns')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "8fc4b016",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>开盘价</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>收盘价</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             开盘价  high   low   收盘价\n",
       "date                              \n",
       "2022-07-01  2.78  2.79  2.76  2.77\n",
       "2022-07-04  2.77  2.77  2.75  2.76\n",
       "2022-07-05  2.77  2.78  2.74  2.76\n",
       "2022-07-06  2.76  2.76  2.70  2.72\n",
       "2022-07-07  2.72  2.74  2.71  2.72"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataWithCName"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "a796aaba",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataWithCName.rename({'low': '最低价'}, axis = 'columns', inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "07085c03",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>开盘价</th>\n",
       "      <th>high</th>\n",
       "      <th>最低价</th>\n",
       "      <th>收盘价</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             开盘价  high   最低价   收盘价\n",
       "date                              \n",
       "2022-07-01  2.78  2.79  2.76  2.77\n",
       "2022-07-04  2.77  2.77  2.75  2.76\n",
       "2022-07-05  2.77  2.78  2.74  2.76\n",
       "2022-07-06  2.76  2.76  2.70  2.72\n",
       "2022-07-07  2.72  2.74  2.71  2.72"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataWithCName"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "23755125",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>开盘价</th>\n",
       "      <th>high</th>\n",
       "      <th>最低价</th>\n",
       "      <th>收盘价</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             开盘价  high   最低价   收盘价\n",
       "date                              \n",
       "2022-07-01  2.78  2.79  2.76  2.77\n",
       "2022-07-04  2.77  2.77  2.75  2.76\n",
       "2022-07-05  2.77  2.78  2.74  2.76\n",
       "2022-07-06  2.76  2.76  2.70  2.72\n",
       "2022-07-07  2.72  2.74  2.71  2.72"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataWithCName"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "8e23639a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>开盘价</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>收盘价</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             开盘价  high   low   收盘价\n",
       "date                              \n",
       "2022-07-01  2.78  2.79  2.76  2.77\n",
       "2022-07-04  2.77  2.77  2.75  2.76\n",
       "2022-07-05  2.77  2.78  2.74  2.76\n",
       "2022-07-06  2.76  2.76  2.70  2.72\n",
       "2022-07-07  2.72  2.74  2.71  2.72"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataWithCName2 = dataWithCName\n",
    "dataWithCName2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b787c5e6",
   "metadata": {},
   "source": [
    "#### 原来的数据不受影响"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "767dd09d",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            open  high   low  close\n",
       "date                               \n",
       "2022-07-01  2.78  2.79  2.76   2.77\n",
       "2022-07-04  2.77  2.77  2.75   2.76\n",
       "2022-07-05  2.77  2.78  2.74   2.76\n",
       "2022-07-06  2.76  2.76  2.70   2.72\n",
       "2022-07-07  2.72  2.74  2.71   2.72"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15a0b1de",
   "metadata": {},
   "source": [
    "#### 把列名全换了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "517b5285",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>开盘价</th>\n",
       "      <th>最高价</th>\n",
       "      <th>最低价</th>\n",
       "      <th>收盘价</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             开盘价   最高价   最低价   收盘价\n",
       "date                              \n",
       "2022-07-01  2.78  2.79  2.76  2.77\n",
       "2022-07-04  2.77  2.77  2.75  2.76\n",
       "2022-07-05  2.77  2.78  2.74  2.76\n",
       "2022-07-06  2.76  2.76  2.70  2.72\n",
       "2022-07-07  2.72  2.74  2.71  2.72"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataWithCName = data.rename({'open': '开盘价', 'close': '收盘价', 'high': '最高价', 'low': '最低价'}, axis='columns')\n",
    "dataWithCName"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7deddc05",
   "metadata": {},
   "source": [
    "#### 这个假装低人一等的date怎么改？尝试加一个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "7d13c69a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>开盘价</th>\n",
       "      <th>最高价</th>\n",
       "      <th>最低价</th>\n",
       "      <th>收盘价</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             开盘价   最高价   最低价   收盘价\n",
       "date                              \n",
       "2022-07-01  2.78  2.79  2.76  2.77\n",
       "2022-07-04  2.77  2.77  2.75  2.76\n",
       "2022-07-05  2.77  2.78  2.74  2.76\n",
       "2022-07-06  2.76  2.76  2.70  2.72\n",
       "2022-07-07  2.72  2.74  2.71  2.72"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataWithCName = data.rename({'open': '开盘价', 'close': '收盘价', 'high': '最高价', 'low': '最低价', 'date': '日期'}, axis='columns')\n",
    "dataWithCName"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a2e63ea",
   "metadata": {},
   "source": [
    "#### 完美主义者不接受 date 的倔强"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "5e931e13",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>开盘价</th>\n",
       "      <th>最高价</th>\n",
       "      <th>最低价</th>\n",
       "      <th>收盘价</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>日期</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             开盘价   最高价   最低价   收盘价\n",
       "日期                                \n",
       "2022-07-01  2.78  2.79  2.76  2.77\n",
       "2022-07-04  2.77  2.77  2.75  2.76\n",
       "2022-07-05  2.77  2.78  2.74  2.76\n",
       "2022-07-06  2.76  2.76  2.70  2.72\n",
       "2022-07-07  2.72  2.74  2.71  2.72"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataWithCNameAndIndex = data.rename({'open': '开盘价', 'close': '收盘价', 'high': '最高价', 'low': '最低价'}, axis='columns')\n",
    "dataWithCNameAndIndex.index = data.index.rename('日期')\n",
    "dataWithCNameAndIndex"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f3e23d7",
   "metadata": {},
   "source": [
    "#### 完美主义者不接受 date 的倔强2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dccb2caf",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "dataWithCNameAndIndex = data.rename({'open': '开盘价', 'close': '收盘价', 'high': '最高价', 'low': '最低价'}, axis='columns')\n",
    "dataWithCNameAndIndex.index.rename('日期', inplace=True)\n",
    "dataWithCNameAndIndex"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ee36496",
   "metadata": {},
   "source": [
    "#### 把列名全换了之另一种方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "e90b5cb4",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>开盘价</th>\n",
       "      <th>收盘价</th>\n",
       "      <th>最高价</th>\n",
       "      <th>最低价</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             开盘价   收盘价   最高价   最低价\n",
       "date                              \n",
       "2022-07-01  2.78  2.79  2.76  2.77\n",
       "2022-07-04  2.77  2.77  2.75  2.76\n",
       "2022-07-05  2.77  2.78  2.74  2.76\n",
       "2022-07-06  2.76  2.76  2.70  2.72\n",
       "2022-07-07  2.72  2.74  2.71  2.72"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataWithCName = data.copy()\n",
    "dataWithCName.columns = ['开盘价', '收盘价', '最高价', '最低价']\n",
    "dataWithCName"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15d9bd3b",
   "metadata": {},
   "source": [
    "#### 原来的数据不受影响"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "b8a842f0",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-07-01</th>\n",
       "      <td>2.78</td>\n",
       "      <td>2.79</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-04</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.77</td>\n",
       "      <td>2.75</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-05</th>\n",
       "      <td>2.77</td>\n",
       "      <td>2.78</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-06</th>\n",
       "      <td>2.76</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.70</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-07-07</th>\n",
       "      <td>2.72</td>\n",
       "      <td>2.74</td>\n",
       "      <td>2.71</td>\n",
       "      <td>2.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            open  high   low  close\n",
       "date                               \n",
       "2022-07-01  2.78  2.79  2.76   2.77\n",
       "2022-07-04  2.77  2.77  2.75   2.76\n",
       "2022-07-05  2.77  2.78  2.74   2.76\n",
       "2022-07-06  2.76  2.76  2.70   2.72\n",
       "2022-07-07  2.72  2.74  2.71   2.72"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ab8f695",
   "metadata": {},
   "source": [
    "### 使用表格里的内容\n",
    "#### 按照座位序号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "23f94bdb",
   "metadata": {},
   "outputs": [],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "120755bd",
   "metadata": {},
   "source": [
    "- 编程思维之 **从零开始**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb134d51",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "data.iloc[0,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0443e7d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.iloc[3, 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "96d14c5c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "data.iloc[0,0], data.iloc[0, 2], data.iloc[0,0] + data.iloc[0, 2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95c1192d",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "data.iloc[0,0], data.iloc[0, 3], data.iloc[0,0] + data.iloc[0, 3]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43d2089f",
   "metadata": {},
   "source": [
    "#### 如何取一个格的数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2724093b",
   "metadata": {},
   "outputs": [],
   "source": [
    "data['close'][4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "65673429",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "data.close[4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b9348175",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.open[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "185fd6bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.loc[data.index[3]].open"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85c8e841",
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime as dt\n",
    "oneDay = dt.datetime(2022, 7, 5)\n",
    "oneDay"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a2737168",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.loc[oneDay]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50e3dd85",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.loc[oneDay].open"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "078655f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.loc[oneDay].close"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1949aaf",
   "metadata": {},
   "source": [
    "### 改变表格里的内容\n",
    "- 复制一份数据来改变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ae2730d",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "dataWillChange = data.copy()\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "038611e6",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "dataWillChange.iloc[0, 0] = 0\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99c70b7e",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataWillChange.open[3] = 100\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9de2a93e",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "dataWillChange['close'][2] = 300\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "465cfeaf",
   "metadata": {},
   "outputs": [],
   "source": [
    "dataWillChange.low = 0\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03510e44",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "dataWillChange.loc[oneDay] = 1\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd95e7cd",
   "metadata": {},
   "source": [
    "#### 我们增加一列吧"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d37c9ceb",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "dataWillChange = data.copy()\n",
    "dataWillChange"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f55885ea",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
